package com.luych.toolbox.data.service.entity;

import com.luych.toolbox.common.enums.DataSourceStatus;
import com.luych.toolbox.common.enums.DataSourceType;
import com.luych.toolbox.common.service.base.BaseEntity;

import javax.persistence.*;

@Entity
@Table(name = "data_source")
public class DataSource extends BaseEntity {

    @Column(name = "name")
    private String name;
    @Column(name = "type")
    @Enumerated(EnumType.STRING)
    private DataSourceType type;
    @Column(name = "host")
    private String host;
    @Column(name = "port")
    private Integer port;
    @Column(name = "db")
    private String db;
    @Column(name = "user")
    private String user;
    @Column(name = "pass")
    private String pass;
    @Column(name = "owner_id")
    private String ownerId;
    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    private DataSourceStatus status;
    @Column(name = "super_user")
    private String superUser;
    @Column(name = "super_pass")
    private String superPass;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DataSourceType getType() {
        return type;
    }

    public void setType(DataSourceType type) {
        this.type = type;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getDb() {
        return db;
    }

    public void setDb(String db) {
        this.db = db;
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public DataSourceStatus getStatus() {
        return status;
    }

    public void setStatus(DataSourceStatus status) {
        this.status = status;
    }

    public String getSuperUser() {
        return superUser;
    }

    public void setSuperUser(String superUser) {
        this.superUser = superUser;
    }

    public String getSuperPass() {
        return superPass;
    }

    public void setSuperPass(String superPass) {
        this.superPass = superPass;
    }

    public String getUrl() {
        if (this.type == null || this.host == null || this.port == null || this.db == null) {
            return null;
        }
        return String.format("jdbc:%s://%s:%d/%s", this.type.getDriver(), this.host, this.port, this.db);
    }
}